package request

import (
	"fox/common"
	"fox/models"
	"reflect"
)

type RolePermission struct {
	Paging
}

type SaveRolePermission struct {
	RoleId       int64 `json:"roleId" binding:"required"`
	PermissionId int64 `json:"permissionId" binding:"required"`
}

type UpdateRolePermission struct {
	ID           int64 `json:"id" binding:"required"`
	RoleId       int64 `json:"roleId" binding:"required"`
	PermissionId int64 `json:"permissionId" binding:"required"`
	Status       int   `json:"status" binding:"omitempty,min=-1,max=1"`
}

func ValidateRolePermissionSortFile(filed string) bool {
	var (
		rolePermission *models.RolePermission
		ele            reflect.Type
	)

	rolePermission = &models.RolePermission{}
	ele = reflect.TypeOf(rolePermission).Elem()
	for i := 0; i < ele.NumField(); i++ {
		var tagSetting = common.ParseTagSetting(ele.Field(i).Tag.Get("gorm"), ";")
		if tagSetting["COLUMN"] == filed {
			return true
		}
	}
	return false
}
